package tree;

/**
 * @Description
 * @Author Firenut
 * @Date 2023-05-04 16:46
 */
public class T100_isSameTree {
    // 思路: 同时遍历树结点并依次比较val值,如果不相等则返回false
    public boolean isSameTree(TreeNode p, TreeNode q) {
        if (p == null && q == null) return true;
        if (p == null || q == null) return false;
        if (p.val != q.val) return false;
        return isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
    }
}
